﻿using System;
using System.Data;
using System.Linq;

namespace LayerEntity.Persona.RecursosHumanos
{
    public class EPlanilla
    {
        #region Constructores
        public EPlanilla(IDataRecord record)
        {
            this.EnPlanilla = Convert.ToBoolean(Convert.ToInt32(record["enplanilla"].ToString()));
            if (EnPlanilla)
            {
                this.IdAfp = (int)record["id_afp"];
                this.FechaInscripcion = (DateTime)record["fecins_planilla"];
            }
            this.IdEstado = (int)record["id_estado"];

            if(IdEstado !=1){
                this.FechaCese = (DateTime)record["fecces_planilla"];
            }
            this.IdPlanilla = (int)record["id_planilla"];
            this.Cuspp = record["cuspp_planilla"].ToString();
            this.Essalud = record["essalud_planilla"].ToString();
            this.IdPersona = record["id_persona"].ToString();            
            this.NumeroHijos = (int)record["numhijos_planilla"];
            this.Sueldo = (Double)record["suel_planilla"];         
            this.FechaIngreso = (DateTime)record["fec_ing_planilla"];
            /*

  id_persona character varying(12) NOT NULL,
  numhijos_planilla integer,
  id_afp integer,
  enplanilla integer,
  fec_ing_planilla date,
             */
        }

        public EPlanilla()
        {
            this.IdPlanilla = 0;
            this.IdAfp = 0;
            this.IdEstado = 0;
            this.Cuspp = string.Empty ;
            this.Essalud = string.Empty;
            this.IdPersona = "";
            this.FechaInscripcion = DateTime.Now;            
            this.NumeroHijos = 0;
            this.Sueldo = 0.0;            
            this.EnPlanilla = false ;
            this.FechaIngreso = DateTime.Now.Date ;
        }
        
        #endregion
         
        #region Propiedades

        public int  IdPlanilla { get; set; }

        public int IdAfp { get; set; }

        public int IdEstado { get; set; }

        public string Cuspp { get; set; }

        public string Essalud { get; set; }

        public string IdPersona { get; set; }

        public DateTime FechaInscripcion { get; set; }

        public DateTime FechaCese { get; set; }

        public int NumeroHijos { get; set; }

        public double Sueldo { get; set; }

        //public int IdLocal { get; set; }

        public bool EnPlanilla { get; set; }

        public DateTime FechaIngreso { get; set; }
        #endregion

        #region Funciones
        public object[] ToObject()
        {
            object[] returnValue = new object[11];
            returnValue[0] = this.IdPlanilla;//_id_planilla
            returnValue[1] = this.Cuspp;//_cuspp_planilla
            returnValue[2] = this.Essalud;//_essalud_planilla
            if (EnPlanilla)
            {
                returnValue[3] = this.FechaInscripcion;//_fecins_planilla
                returnValue[8] = this.IdAfp;//_id_afp
            }
            else
            {
                returnValue[3] = DBNull.Value;//_fecins_planilla
                returnValue[8] = DBNull.Value;//_id_afp
            }
            returnValue[4] = this.Sueldo;//_suel_planilla
            returnValue[5] = this.FechaCese;//_fecces_planilla
            returnValue[6] = this.IdPersona;//_id_persona
            returnValue[7] = this.NumeroHijos;//_numhijos_planilla
            returnValue[9] = Convert.ToInt32(this.EnPlanilla);//_enplanilla
            returnValue[10] = this.FechaIngreso;//_fec_ing_planilla
            return returnValue;
        }
        #endregion
    }
}